<script>
export default {
  onLaunch: function () {
    // 展示本地存储能力
    this.readUUID();
  },
  methods: {
    readUUID() {
      const storage = uni.getStorageSync;
      this.globalData.usrserviceuuid = storage('usrserviceuuid') || "0000FFE0-0000-1000-8000-00805F9B34FB";
      this.globalData.usrrxduuid = storage('usrrxduuid') || "0000FFE2-0000-1000-8000-00805F9B34FB";
      this.globalData.usrtxduuid = storage('usrtxduuid') || "0000FFE1-0000-1000-8000-00805F9B34FB";
      this.globalData.muuidSel = storage('lastsel') || 0;
      console.log(this.globalData.usrrxduuid);
      console.log("Read = ", this.globalData.usrserviceuuid, this.globalData.usrtxduuid, this.globalData.usrrxduuid);
    },
    readSetting() {
      this.readUUID();
      const storage = uni.getStorageSync;
      this.globalData.mautoSendInv = storage('autoSendInv') || 100;
      this.globalData.msendText = storage('sendText') || "1024";
      this.globalData.muuidSel = storage('lastsel') || 0;
      switch (this.globalData.muuidSel) {
        case 0:
          this.globalData.mserviceuuid = "0000FFE0-0000-1000-8000-00805F9B34FB";
          this.globalData.mtxduuid = "0000FFE1-0000-1000-8000-00805F9B34FB";
          this.globalData.mrxduuid = "0000FFE2-0000-1000-8000-00805F9B34FB";
          break;
        case 1:
          this.globalData.mserviceuuid = "0000FFE0-0000-1000-8000-00805F9B34FB";
          this.globalData.mtxduuid = "0000FFE1-0000-1000-8000-00805F9B34FB";
          this.globalData.mrxduuid = "0000FFE2-0000-1000-8000-00805F9B34FB";
          break;
        case 2:
          this.globalData.mserviceuuid = this.globalData.usrserviceuuid;
          this.globalData.mtxduuid = this.globalData.usrtxduuid;
          this.globalData.mrxduuid = this.globalData.usrrxduuid;
          break;
      }
      console.log("readSetting ", this.globalData.mautoSendInv, this.globalData.msendText);
    },
    saveSetting(time, text) {
      uni.setStorageSync('autoSendInv', time);
      uni.setStorageSync('sendText', text);
      console.log("WriteSetting ", time, text);
    },
    savelastsel(sel) {
      uni.setStorageSync('lastsel', sel);
      console.log("Writelastsel ", sel);
    },
    saveusrUUID(id_s, id_t, id_r) {
      this.globalData.usrserviceuuid = id_s;
      this.globalData.usrrxduuid = id_r;
      this.globalData.usrtxduuid = id_t;
      uni.setStorageSync('usrserviceuuid', id_s);
      uni.setStorageSync('usrrxduuid', id_r);
      uni.setStorageSync('usrtxduuid', id_t);
      console.log("Save usr = ", id_s, id_t, id_r);
    },
  },
  globalData: {
    mserviceuuid: "0000FFE0-0000-1000-8000-00805F9B34FB",
    mtxduuid: "0000FFE1-0000-1000-8000-00805F9B34FB",
    mrxduuid: "0000FFE2-0000-1000-8000-00805F9B34FB",
    usrserviceuuid: "0000FFE0-0000-1000-8000-00805F9B34FB",
    usrtxduuid: "0000FFE1-0000-1000-8000-00805F9B34FB",
    usrrxduuid: "0000FFE2-0000-1000-8000-00805F9B34FB",
    muuidSel: 0,
    mautoSendInv: 10,
    msendText: "",
    ble_device: null,
  },
};
</script>

<style lang="scss">
	@import '@/uni_modules/uv-ui-tools/index.scss';
	@import "@/common/demo.scss";

	/*每个页面公共css */
	.uv-demo-block {
		margin-bottom: 22rpx;
		margin-left: 22rpx;
		margin-right: 22rpx;
	}

	.uv-page {
		padding: 15px 15px 40px;
	}
	
	page {
	  color: #333;
	  font-size: 16px;
	  background: #f8f8f8;
	  min-height: 100vh;
	  box-sizing: border-box;
	  // padding: 0 0 100rpx;
	  -webkit-font-smoothing: antialiased;
	  font-family: 'PingFang SC', Helvetica, 'STHeiti STXihei', 'Microsoft YaHei', Tohoma, Arial, sans-serif;
	}
	
	.demo-margin-left {
	  margin-left: 10px;
	}
	
	.demo-margin-right {
	  margin-right: 10px;
	}
	
	.demo-margin-bottom {
	  display: block;
	  margin-bottom: 15px;
	}

	/**app.wxss**/
	// .container {
	// 	height: 100%;
	// 	display: flex;
	// 	flex-direction: column;
	// 	align-items: center;
	// 	justify-content: space-between;
	// 	padding: 200rpx 0;
	// 	box-sizing: border-box;
	// }
</style>